//
//  CycNewRefreshView.swift
//  微博cyc
//
//  Created by cyc on 16/3/8.
//  Copyright © 2016年 cyc. All rights reserved.
//

import UIKit

class CycNewRefreshView: UIView {
    //7-4-1属性连线
    @IBOutlet weak var tipIcon: UIImageView!
    //下拉view
    @IBOutlet weak var
    TipView: UIView!
    //正在加载的图片
    @IBOutlet weak var LoadingView: UIImageView!
    /// 从xib加载view7-1
    class func refreshView() -> CycNewRefreshView {
        return NSBundle.mainBundle().loadNibNamed("CycNewRefreshView", owner: nil, options: nil).last as! CycNewRefreshView
        //has not been implemented: file /Users/cyc/Downloads/swift/02代码/CycNewRefreshctrol.swift
        // 如果选择是CycNewRefreshctrol就会报错要选择CycNewRefreshView的
    }
    /**
     箭头旋转
     
     - parameter isUp: 7-4 旋转方向
     */
    func rotationTipIcon(isUp: Bool) {
        UIView.animateWithDuration(0.25) { () -> Void in
            self.tipIcon.transform = isUp ? CGAffineTransformMakeRotation(CGFloat(M_PI - 0.001)) : CGAffineTransformIdentity
        }
    }
    //7-5-1
    /**
    开始旋转
    */
    func startloading(){
        //7-5-5避免动画重复
        let animKey="rotationAnim"
        //判断动画是否添加过了
        
        if let _ = LoadingView.layer.animationForKey(animKey){
            //能够进来说明已经添加动画
               print("已经添加了动画")
            return
        }
       // 7-5-2隐藏上面的tipView旋转
        TipView.hidden=true
        // loadingview旋转
        let rotationAnim=CABasicAnimation(keyPath: "transform.rotation")
        rotationAnim.toValue = M_PI * 2
        rotationAnim.repeatCount=MAXFLOAT
        rotationAnim.duration=0.25
        rotationAnim.removedOnCompletion=false
        //7-5-2添加动画
        // 7-5-6 解决重复动画的问题 animKey
         LoadingView.layer.addAnimation(rotationAnim, forKey: animKey)
        
        
        
        
    }
    //7-6
    /**
     停止旋转显示箭头
    */
    func stopLoading(){
        //移除动画
          LoadingView.layer.removeAllAnimations()
        
        
        //显示上面的tipview
          TipView.hidden=false
        
        
    }

}
//7-5下拉刷新完成
//7-6自定义刷新控件完成
//7-6-6已经完成刷新新控件
